import {
	BaseUrl,
	formatDishesScore
} from "./config"

import dayjs from "dayjs"
/**
 * 查询今日菜单
 */
export function getDailyMenuDishes(date) {

	const dateStr = dayjs(date).format("YYYY-MM-DD")

	return uni.request({
		method: "GET",
		url: BaseUrl + '/dailyMenu/get',
		data: {
			date: dateStr
		}
	}).then(res => {
		// console.log("查询今日菜单", res.data.data);
		if (!res.data.data?.dishes) {
			return {
				dishes: []
			}
		}
		res.data.data.dishes = res.data.data.dishes.map(e => {
			e.dishTypeId = parseInt(e.dishTypeId)
			return e
		})
		return res.data.data
		// const id = res.data.data?.id
		// const dishes = formatDishesScore(res.data.data?.dishes || [])
		// const menuTypeId = res.data.data?.menuTypeId
		// return {
		// 	id,
		// 	dishes,
		// 	menuTypeId
		// }
	})
}

/**
 * 创建今日菜单
 */
export function createDailyMenu({
	date,
	menuTypeId,
	dishIds
}) {
	const dateStr = dayjs(date).format("YYYY-MM-DD")
	return uni.request({
		method: "POST",
		url: BaseUrl + '/dailyMenu/creat',
		data: {
			date: dateStr,
			menuTypeId,
			dishIds
		}
	}).then(res => res.data)
}


/**
 * 修改今日菜单
 */
export function updateDailyMenuById({
	id,
	date,
	menuTypeId,
	dishIds

}) {
	console.log("修改今日菜单", date);
	const dateStr = dayjs(date).format("YYYY-MM-DD")
	return uni.request({
		method: "PUT",
		url: BaseUrl + '/dailyMenu/update',
		data: {
			id,
			date: dateStr,
			menuTypeId,
			dishIds
		}
	}).then(res => res.data)
}